local lsp_lingying = fk.CreateSkill {
    name = "lsp_lingying",
    anim_type = "drawcard",
    tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
    ["lsp_lingying"] = "灵盈",
    [":lsp_lingying"] = "你每失去三张手牌，摸一张牌并获得一点盈能；准备阶段，若盈能达到上限，你可以变身；当盈能为0时，你退出变身(盈能至多为5点)。",

    ["@lsp_lingying"] = "盈能",
}
lsp_lingying:addEffect(fk.AfterCardsMove, {
    mute = true,
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(lsp_lingying.name)
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardsMove then
            local i = 0
            for _, move in ipairs(data) do
                if move.from == player then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerHand then
                            i = i + 1
                        end
                    end
                end
            end
            if i > 0 then
                for _ = 1, i, 1 do
                    room:addPlayerMark(player, "lsp_lingying", 1)
                    if player:getMark("lsp_lingying") > 2 then
                        room:setPlayerMark(player, "lsp_lingying", 0)
                        player:drawCards(1, lsp_lingying.name)
                        if player:getMark("@lsp_lingying") < 5 then
                            room:addPlayerMark(player, "@lsp_lingying", 1)
                        end
                    end
                end
            end
        end
    end,
})
lsp_lingying:addEffect(fk.EventPhaseStart, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(lsp_lingying.name) and target == player and player.phase == Player.Start and
            player:getMark("@lsp_lingying") == 5
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, { skill_name = lsp_lingying.name, prompt = "灵盈：能量已满！是否变身？" })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local isDeputy = true
        if player.general == "lsp__liyue" then --是否改变副将案例
            isDeputy = false
        end
        room:notifySkillInvoked(player, lsp_lingying.name, "big")
        room:changeHero(player, "lsp__liyue_ex", false, isDeputy, true, false)
    end,
})
return lsp_lingying
